﻿/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.utils.uArray 
{
	
	public function uArray() 
	{
		
	}
	public static function copy(ori:Array) {
		var arr = [];
		for (var i = 0; i<ori.length; i++) 	arr[i] = ori[i];
		return arr;
	}
	public static function hasVV(arr, vv) {
		for (var i = 0; i<arr.length; i++) {
			if (arr[i] == vv) return i;
		}
		return  -1
	} 
	public static function del(arr:Array, vv) {
		var arr = copy(arr); 
		var id =hasVV(arr,vv); 
		if (id == -1) return arr;
		arr.splice(id, 1);
		return  arr
	}
	static function compare(arr1, arr2) {
		for (var i = 0; i<arr1.length; i++) {
			if (arr1[i] != arr2[i]) return false;
		}
		return true;
	}
	public static function randomNN(min, max):Array {
		var arr = [];
		for (var i = min; i<=max; i++) arr[i] = i;
		arr.sort(randomsort);
		return arr;
	} 
	public static function random(arr):Array {
		return copy(arr).sort( randomsort);
	}
	public static function randomsort(a, b) {
		return Math.random()>.5 ? -1 : 1;
	}
	public static function getVVunderArrV1(mc_arr:Array, lvl:String) {
		return getVVunderArr(mc_arr, lvl.split('.'));
	}
	public static function getVVunderArr(ori, lvl) {
		var arr = [];
		for (var i = 0; i<ori.length; i++) {
			//trace(ori[i]+' - '+lvl);
			var vv = getVV(ori[i], copy(lvl));
			//trace(vv);
			arr[i] = vv;
		}
		return arr;
	}
	static function getVV(data, lvl) {
		var a1 = lvl.shift();
		if (lvl.length == 0) {
			return data[a1];
		} else {
			return getVV(data[a1], lvl);
		}
		//trace(data._name); 
		//trace('32 -> '+data);
		//trace('33 -> '+data[a1]);
		//trace('33 -> '+data[a1]._name);
		//return getVV(arr); 
	}
	public static function hasItVV(arr, vv) {
		for (var i = 0; i<arr.length; i++) {
			if (arr[i] == vv) {
				return true;
			}
		}
		return false;
	}
	public static function ck2D(AxB):Array {
		var xn:Number = Number(AxB.split('*')[0]);
		var yn:Number = Number(AxB.split('*')[1]);
		var arr = [];
		var z = 0;
		for (var i = 0; i<yn; i++) {
			arr[i] = [];
			for (var j = 0; j<xn; j++) {
				arr[i][j] = z;
				z++;
			}
			//trace(arr[i]);
		}
		var len = (arr.length);
		//trace('yn  - '+xn);
		for (var i = 0; i<xn; i++) {
			arr[i+len] = [];
			//trace(i+xn);
			for (var j = 0; j<yn; j++) {
				arr[i+len][j] = i+j*xn;
			}
			//trace(arr[i+len]);
		}
		return arr;
	}
	public static function compareArray(a, b):Boolean {
		if (a.length != b.length) {
			return false;
		}
		for (var i = 0; i<a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	
}